<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>

<head>
	<script type="text/javascript">
		function save(){
			document.forms[0].codDepto.value = $.trim(document.forms[0].codDepto.value);
			document.forms[0].nombreDepto.value = $.trim(document.forms[0].nombreDepto.value);
			
			if(document.forms[0].codDepto.value == '' || document.forms[0].nombreDepto.value == '' ){
				$('#errorCodDepto').show();
				return false
			}
			
			document.forms[0].typeModif.value = 'new';
			document.forms[0].submit();
		}

		function cancel(){
			document.forms[0].action = 'listarDepartamentoAction';
			document.forms[0].submit();
		}
	</script>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link href="estilos/style.css" rel="stylesheet" type="text/css" />
	<title>LABTEC - Agregar Departamento</title>
</head>

<body>
	<div id="header">
		    <jsp:include page="../jsp/menuAdministrador.jsp" />
	</div>
	<div class="sheet">
		<div class="sheet-tl"></div>
		<div class="sheet-tr"></div>
		<div class="sheet-bl"></div>
		<div class="sheet-br"></div>
		<div class="sheet-tc"></div>
		<div class="sheet-bc"></div>
		<div class="sheet-cl"></div>
		<div class="sheet-cr"></div>
		<div class="sheet-cc"></div>
		<div class="sheet-body">
		
			<s:if test="hasActionMessages()">
				<div class="error">
					<s:actionmessage />
				</div>
			</s:if>
					<div id="errorCodDepto" class="error" style="display: none;">
									<ul class="actionMessage">
					            	    <li>
					            	    	<span>
					            	    		Campos obligatorios: El código y nombre del departamento no pueden estar vacíos.
					            	    	</span>
					            	    </li>
									</ul>
								</div>
			<s:if test="hasFieldErrors()">
				<div class="error">
					<s:fielderror/></div>
			</s:if>
			
			<h5 class="postcontent">
				Agregar nuevo Departamento
			</h5>
			<br />
			<s:form action="gestionDepartamentoAction">
				<s:hidden name="typeModif"></s:hidden>
				
				<table width="100%">
					<tr>
						<td>
							<s:textfield name="codDepto" required="true" maxlength="5" label="Cod. Departamento"/>
						</td>
						<td>
							<s:textfield name="nombreDepto" required="true" maxlength="30" label="Nombre del departamento"/>
						</td>
					</tr>
					<tr align="right" height="70px">
						<td colspan="4">
							<input type="button" value="Cancelar" onclick="cancel()"/>
							<input type="button" value="Guardar" onclick="save()"/>
						</td>
					</tr>
				</table>
			
			</s:form>
		</div>
	</div>
</body>
</html>